#ifndef __SEM_H__
#define __SEM_H__
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/types.h> 
#include <stdlib.h>
#include <stdint.h>

#include "../cgi/cgic.h"


#define N 1024

key_t key_info;
int semid;
struct env_info *shm_buf;
struct env_info
{
	uint8_t head[3];	 //标识位st:
	uint8_t type;		 //数据类型
	uint8_t snum;		 //仓库编号
	uint8_t temp[2];	 //温度	
	uint8_t hum[2];		 //湿度
    uint8_t x;			 //三轴信息
    uint8_t y;			 
    uint8_t z;			 

	uint32_t ill;		 //光照
	uint32_t bet;		 //电池电量
	uint32_t adc; 		 //电位器信息
};


union semun {
	int              val;    /* Value for SETVAL */
	struct semid_ds *buf;    /* Buffer for IPC_STAT, IPC_SET */
	unsigned short  *array;  /* Array for GETALL, SETALL */
	struct seminfo  *__buf;  /* Buffer for IPC_INFO
								(Linux-specific) */
};




int init_sem(int semid, int num, int val);

int sem_p(int semid, int num); //申请资源,P操作

int sem_v(int semid, int num); //释放资源V操作
void init_mem(void);
void fisrt_init_sem(void);
#endif
